package com.mycompany.System.controller;

import com.mycompany.System.entity.wxbase.AccessToken;
import com.mycompany.System.entity.wxbase.FButton;
import com.mycompany.System.entity.wxbase.Menu;
import com.mycompany.System.entity.wxbase.SButton;
import com.mycompany.mvc.utils.SystemUtil;
import com.mycompany.mvc.weixinUtils.WxHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Jintao_Ma on 2017/9/10.
 */
public class MenuController {

    private static Logger log = LoggerFactory.getLogger(MenuController.class);

    public static void main(String[] args) {

        // 调用接口获取access_token
        AccessToken at = WxHttpUtil.getAccessToken();

        if (null != at) {
            // 调用接口创建菜单
            int result = WxHttpUtil.createMenu(getMenu(), at.getToken());

            // 判断菜单创建结果
            if (0 == result)
            // log.info("菜单创建成功！");
            System.out.println("菜单创建成功");
            else
            // log.info("菜单创建失败，错误码：" + result);
            System.out.println("菜单创建失败，错误码"+result);
        }
    }

    /**
     * 组装菜单数据
     *
     * @return
     */
    private static Menu getMenu() {
        SButton btn11 = new SButton();
        btn11.setName("天气预报");
        btn11.setType("click");
        btn11.setKey("11");

        SButton btn12 = new SButton();
        btn12.setName("公交查询");
        btn12.setType("click");
        btn12.setKey("12");

        SButton btn13 = new SButton();
        btn13.setName("周边搜索");
        btn13.setType("click");
        btn13.setKey("13");

        SButton btn14 = new SButton();
        btn14.setName("历史上的今天");
        btn14.setType("click");
        btn14.setKey("14");

        SButton btn21 = new SButton();
        btn21.setName("歌曲点播");
        btn21.setType("click");
        btn21.setKey("21");

        SButton btn22 = new SButton();
        btn22.setName("经典游戏");
        btn22.setType("click");
        btn22.setKey("22");

        SButton btn23 = new SButton();
        btn23.setName("美女电台");
        btn23.setType("click");
        btn23.setKey("23");

        SButton btn24 = new SButton();
        btn24.setName("人脸识别");
        btn24.setType("click");
        btn24.setKey("24");

        SButton btn25 = new SButton();
        btn25.setName("聊天唠嗑");
        btn25.setType("click");
        btn25.setKey("25");

        SButton btn31 = new SButton();
        btn31.setName("Q友圈");
        btn31.setType("click");
        btn31.setKey("31");

        SButton btn32 = new SButton();
        btn32.setName("电影排行榜");
        btn32.setType("click");
        btn32.setKey("32");

        SButton btn33 = new SButton();
        btn33.setName("幽默笑话");
        btn33.setType("click");
        btn33.setKey("33");

        FButton mainBtn1 = new FButton();
        mainBtn1.setName("生活助手");
        mainBtn1.setsButtons(new SButton[] { btn11, btn12, btn13, btn14 });

        FButton mainBtn2 = new FButton();
        mainBtn2.setName("休闲驿站");
        mainBtn2.setsButtons(new SButton[] { btn21, btn22, btn23, btn24, btn25 });

        FButton mainBtn3 = new FButton();
        mainBtn3.setName("更多体验");
        mainBtn3.setsButtons(new SButton[] { btn31, btn32, btn33 });

        /**
         * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项
         */
        Menu menu = new Menu();
        menu.setfButtons(new FButton[] { mainBtn1, mainBtn2, mainBtn3 });

        return menu;
    }

}
